package com.wxx.notion;

import cn.hutool.core.bean.BeanUtil;
import com.wxx.bean.ProBean;
import com.wxx.contance.Contance;
import com.wxx.message.DingDingSender;
import com.wxx.message.IMessageSender;
import com.wxx.utils.TraceIdUtil;
import org.slf4j.MDC;

import java.io.File;
import java.io.FileInputStream;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Properties;

/**
 * @author: wxx
 * @date: 2024-08-16 17:09
 * @description 开机发送开机信息
 */
public class StartComputer {

    static SimpleDateFormat instance = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static IMessageSender sender;

    public static void main(String[] args) throws Exception {
        String traceLogId = TraceIdUtil.getTraceLogId();
        MDC.put(Contance.TRACE_ID, traceLogId);

        Properties properties = new Properties();
        properties.load(new FileInputStream(new File(args[0])));
        ProBean proBean = new ProBean();
        BeanUtil.copyProperties(properties, proBean);

        sender = new DingDingSender();
        sender.init(proBean);

        String hostName = InetAddress.getLocalHost().getHostName();
        String content = proBean.getHostName() + "-" + hostName + " " + instance.format(System.currentTimeMillis()) + "开机了";
        sender.sendMessage(content);
        MDC.clear();
    }
}
